#include <errors.h>


static volatile int last_error = ERR_NO_ERROR;


static const char* messages[ERR_LAST] = {
  "no error",
  "unknow error",
  "memory allocation error",
  "io error",
  "illegal move",
  "illegal position",
  "ill formed SAN move",
  "ambiguous SAN move",
  "undo is not possible",
  "book file format error"
};


int error_last()
{
  return last_error;
}


int error_set(int code)
{
  last_error = code;
  return code;
}


const char* error_string(int code)
{
  if (code < 0 || code >= ERR_LAST)
    return "invalid error code";
  return messages[code];
}
